<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <link href="../css/personalInfo.css" rel="stylesheet" type="text/css"/>
</head>
<body>
    <div style="width: 100%;height:800px;position: center;background-color: #dddddd;">
    <div class="div" style="margin-top: 10px">
        <label class="label">用户组：</label>
        <select id="groupid" autofocus="autofocus" class="input">
            <option value="请选择">请选择</option>
        </select>
    </div>
    <div class="div" style="margin-top: 10px">
        <label class="label">用户名：</label><input class="input" id="userName" name="userName" type="text" placeholder="请输入用户名">
    </div>
    <div class="div">
        <label class="label">密  码：</label><input class="input" id="password" name="password" type="password" placeholder="请输入密码">
    </div>
    <div class="div">
        <label class="label">姓  名：</label><input class="input" id="realName" name="realName" type="text" placeholder="请输入真实姓名">
    </div>
    <div class="div">
        <label class="label">身份证：</label><input class="input" id="identity" name="identity" type="text" placeholder="请输入身份证号码">
    </div>
    <div class="div">
        <label class="label">联系电话：</label><input class="input" id="phone" name="phone" type="text" placeholder="请输入联系电话">
    </div>
    <div class="div">
        <label class="label">备  注：</label><input class="input" id="remark" name="remark" type="text" placeholder="请输入备注信息">
    </div>
    <div class="div"><input class="btn" type="submit" id="submit" name="submit" value="添加用户" onclick="addUser()"></div>
</div>

<script type="text/javascript" src="../lib/jquery.min.js"></script>
<script type="text/javascript" src="../lib/H-ui.min.js"></script>
    <script type="text/javascript" src="../lib/util.js"></script>
    <script type="text/javascript">

        //页面加载处理
        $(document).ready(function () {
            var html = "";
            var groups=userGroup();
            for(var i=0;i<groups.length;i++){
                var row=groups[i];
                if( row.groupId == groupid){
                    var rowHtml="<option value=\""+row.groupId+"\" selected>"+row.desc+"</option>";
                }else{
                    var rowHtml="<option value=\""+row.groupId+"\">"+row.desc+"</option>";
                }

                html=html+rowHtml;
            }

            $("#groupid").append(html);

        });

        //添加用户
        function addUser() {
            var groupId = $("#groupid").val();
            var userName = $("#userName").val();
            var password = $("#password").val();
            var realName = $("#realName").val();
            var identity = $("#identity").val();
            var phone = $("#phone").val();
            if(userName == "" || userName == null){

                alert("用户名不能为空！");

            }else if(password == "" || password == null){

                alert("密码不能为空！");
            }else if(realName == "" || realName == null){

                alert("真实姓名不能为空！");

            }else if(identity == "" || identity == null){

                alert("身份证号码不能为空！");

            }else{

                $.ajax({
                    type: "post",
                    url: "/user/insertOne",
                    data: {
                        groupid:groupId,
                        username:userName,
                        password:password,
                        realname:realName,
                        identity:identity,
                        phone:phone,
                        remark:"测试",
                        status:1

                    },
                    dataType: "json",
                    success: function (data) {
                        var status=data.status;
                        var msg=data.msg;
                        if(status == 0){
                            //window.location.reload();
                            //alert(userName+"添加成功！");

                            //window.parent.location.href = "userManager.html";
                            window.opener = null;
                            window.open('', '_self');
                            window.close();

                            var _body = window.parent;
                            //_body.location.href = "userManager.html";
                            var _iframe1=_body.parent.document.getElementById('right');
                            _iframe1.contentWindow.location.reload(true);
                            pageSkip(1);

                        }else{
                            alert(msg);
                        }

                    },
                    fail:function (data) {
                        alert(JSON.stringify(data))
                    },
                    error: function(xhr) {
                        // report error
                        alert('Error' + JSON.stringify(xhr))
                    }
                });






            }

        }





    </script>

</body>
</html>